/* eslint-disable complexity */
const api = require('../../utils/api.js');
const util = require('../../utils/utils.js');
const internal = require('../../utils/international.js');
const app = getApp();
Page({
  data: {
    total_price: 0,
    address: null,
    express_price: 0.0,
    content: '',
    offline: 0,
    offlineClick: false,
    express_price_1: 0.0,
    name: '',
    mobile: '',
    IDcardNo: '',
    integral_radio: 2,
    new_total_price: 0,
    show_card: false,
    payment: -1,
    show_payment: false,
    is_overlay: 0,
    chooseAddr: false,
    chooseShop: false,
    attachment_url: app.siteInfo.attachment_url,
    open_setting: false,
    unit: '',
    verify_day: '',
    card_coupon_list: [],
    showCardCouponList: false,
    integral_rule_check: 1,
    paytype: -1,
    num: 0,
    multiArray: [[], []],
    multiIndex: [0, 0],
    mentionedIndex: 0,
    btnFreezen: false,
    couponPicker: false, // 优惠券改版
    curCouponArr: [],
    callCount: 0, // 记录调用接口的次数
    imgUrl: app.imgUrl,
    show_pay_btn: true,
    pay_now: internal.getOrderStatus('pay_now'),
  },

  timeRange: function(timeRang) {
    // 获取时间区间
    let strb = timeRang.split('-')[0].split(':');
    if (Number(strb.length) !== 2) {
      return false;
    }

    let stre = timeRang.split('-')[1].split(':');
    if (Number(stre.length) !== 2) {
      return false;
    }

    let b = new Date();
    let e = new Date();
    let n = new Date();

    b.setHours(strb[0]);
    b.setMinutes(strb[1]);

    e.setHours(stre[0]);
    e.setMinutes(stre[1]);

    if ((n.getTime() <= b.getTime()) || (n.getTime() < e.getTime())) {
      return true;
    } else {
      return false;
    }
  },

  bindMultiPickerChange: function(e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    let data = e.currentTarget.dataset;
    // let estimated_data = data.estimated_data;
    let estimated_data = data.estimated_data;
    let multiArray = estimated_data.multiArray;
    let index = data.index;
    let multiIndex = e.detail.value;
    estimated_data.multiIndex = multiIndex;
    if (index === -1) {
      this.setData({
        estimated_data: estimated_data,
        [`estimated_data.estimated_date`]:
          multiArray[0][multiIndex[0]] + ' ' + multiArray[1][multiIndex[1]],
      });
    } else {
      this.setData({
        [`order_info[${index}].estimated_data`]: estimated_data,
        [`order_info[${index}].estimated_date`]:
          multiArray[0][multiIndex[0]] + ' ' + multiArray[1][multiIndex[1]],
      });
    }
  },

  bindMentionedPickerChange(e) {
    let { order_info } = this.data;
    let { index, mentioned_data } = e.currentTarget.dataset;
    let {
      mentionedArray,
      mentionedIdx,
      timeSplice,
    } = e.currentTarget.dataset.mentioned_data;
    mentioned_data.mentionedIdx = e.detail.value;

    if (index === -1) {
      this.setData({
        mentioned_data,
      });
    } else {
      this.setData({
        [`order_info[${index}].mentioned_data`]: mentioned_data,
        [`order_info[${index}].self_mention_date`]:
          timeSplice.length > 0 ? mentionedIdx[0] : mentionedIdx[0] + 1,
        [`order_info[${index}].self_mention_time`]:
          Number(order_info[index].offline) === 1
            ? mentionedArray[1][mentionedIdx[1]]
            : '',
      });
    }
  },

  bindMultiPickerColumnChange(e) {
    // console.log('修改的列为', e.detail.column, '，值为', e.detail.value);

    let dataset = e.currentTarget.dataset;
    let data = dataset.estimated_data;
    let index = dataset.index;
    let isMulti = this.data.isMulti;
    data.multiIndex[e.detail.column] = e.detail.value;

    switch (e.detail.column) {
      case 0:
        switch (data.multiIndex[0]) {
          case 0:
            data.multiArray[1] = data.timeSplice;
            break;
          case 1:
            data.multiArray[1] = data.dataItem;
            break;
          case 2:
            data.multiArray[1] = data.dataItem;
            break;
        }
        data.multiIndex[1] = 0;
        break;
    }
    if (isMulti) {
      this.setData({
        [`order_info[${index}].estimated_data`]: data,
      });
    } else {
      this.setData({
        estimated_data: data,
      });
    }

  },

  bindMentionedPickerColumnChange(e) {
    // console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
    let { index, mentioned_data } = e.currentTarget.dataset;
    mentioned_data.mentionedIdx[e.detail.column] = e.detail.value;

    switch (e.detail.column) {
      case 0:
        switch (mentioned_data.mentionedIdx[0]) {
          case 0:
            mentioned_data.mentionedArray[1] =
              mentioned_data.timeSplice.length === 0
                ? mentioned_data.timeItem
                : mentioned_data.timeSplice;
            break;
          default: mentioned_data.mentionedArray[1] = mentioned_data.timeItem;
        }
        mentioned_data.mentionedIdx[1] = 0;
        break;
    }

    if (index === -1) {
      this.setData({
        mentioned_data,
      });
    } else {
      this.setData({
        [`order_info[${index}].mentioned_data`]: mentioned_data,
      });
    }
  },

  addDate(date, days) {
    // if (days == undefined || days == '') {
    //   days = 1;
    // }
    date = new Date(date);
    date.setDate(date.getDate() + days);
    let month = date.getMonth() + 1;
    let day = date.getDate();
    return (
      date.getFullYear() +
      '/' +
      this.getFormatDate(month) +
      '/' +
      this.getFormatDate(day)
    );
  },

  getFormatDate(arg) {
    if (!arg) {
      return '';
    }
    let re = String(arg);
    if (re.length < 2) {
      re = '0' + re;
    }
    return re;
  },

  getTime(day, time, dataTime) {
    let that = this;
    dataTime = dataTime.replace(/-/g, '/');
    let timeList = time.split('-');
    let num = that.getHour(timeList[0]);
    let length = that.getHour(timeList[1]) - that.getHour(timeList[0]);
    let dataItem = [];
    let timeItem = '';
    let begin_time = that.getHour(timeList[0]);
    for (let i = 0; i < length; i++) {
      timeItem =
        (that.getFormatDate(begin_time) || '00') +
        ':00-' +
        that.getFormatDate(begin_time + 1) +
        ':00';
      begin_time++;
      dataItem.push(timeItem);
    }

    let multiArray = [[], []];
    let multiIndex = [0, 0];
    for (let i = 0; i < day; i++) {
      let data = this.addDate(dataTime, i);
      multiArray[0].push(data);
    }
    let dataTimelength = new Date(dataTime).getHours() - num;
    let timeSplice = that.copyobj(dataItem);
    timeSplice.splice(0, dataTimelength);
    multiArray[1] = timeSplice;
    let data = {
      dataItem: dataItem,
      timeSplice: timeSplice,
      multiArray: multiArray,
      multiIndex: multiIndex,
      estimated_date:
        multiArray[0][multiIndex[0]] + ' ' + multiArray[1][multiIndex[1]],
    };
    return data;
    // this.setData({
    //   dataItem: dataItem,
    //   timeSplice: time,
    //   multiArray: multiArray,
    // })
  },

  copyobj(a) {
    let c = [];
    c = JSON.parse(JSON.stringify(a));
    return c;
  },

  getHour(time, timeItem) {
    let data = '2019/01/01 ' + time;
    return new Date(data).getHours();
  },

  push(day, dataItem, dataTime) {
    let multiArray = [[], []];
    for (let i = 0; i < day; i++) {
      let data = this.addDate(dataTime, i + 1);
      multiArray[0].push(data);
    }
    let length = new Date(dataTime).getHours() - 8;
    let time = dataItem;
    time.splice(0, length);
    multiArray[1] = time;
    let data = {
      dataItem: this.data.dataItem,
      timeSplice: time,
      multiArray: multiArray,
      multiIndex: [0, 0],
    };
    return data;
    // this.setData({
    //   dataItem: dataItem,
    //   timeSplice: time,
    //   multiArray: multiArray,
    // })
  },

  onLoad(options) {
    let that = this;
    let opts = options || {};
    app.pageOnLoad(this);
    app.loadShopSetting().then(res => {
      that.setData({
        checkmobile: res.check_mobile,
        verify_day: res.verify_day,
      });
    });
    app.loadCurrencyUnit().then(res => {
      that.setData({
        unit: res.unit,
        currency: res.currency || '',
      });
    });
    let time = util.formatData(new Date());
    let isMulti = app.ws_micro_shop_globalData && app.ws_micro_shop_globalData.isMulti; // 是否为多店
    let isSingle = app.ws_micro_shop_globalData && app.ws_micro_shop_globalData.isSingle; // 是否为单店
    let goods_id_list;
    if (options.goods_id_list) {
      goods_id_list = JSON.parse(decodeURIComponent(options.goods_id_list));
    }
    this.setData({
      options: opts,
      store: wx.getStorageSync('store'),
      time: time,
      opts,
      isMulti,
      isSingle,
      version_type: app.ws_micro_shop_globalData.version_type,
      goods_id_list,
    });
    this.getOrderData(options);
  },

  onShow() {
    let address = wx.getStorageSync('picker_address');
    if (address) {
      this.setData({
        address: address,
        name: address.name,
        mobile: address.mobile,
      });
      wx.removeStorageSync('picker_address');
      this.getOrderData(this.data.options); // 切换地址后，重新请求订单数据。
    }
  },

  getIDcardNumber(e) {
    this.setData({
      IDcardNo: e.detail.value,
    });
  },
  // 买家留言
  bindkeyinput(e) {
    if (this.data.isMulti) {
      const cb = store => {
        store.content = e.detail.value;
        return store;
      };
      this.prepareMultiData(e, cb);
    } else {
      this.setData({
        content: e.detail.value,
      });
    }
  },
  KeyName(e) {
    this.setData({
      name: e.detail.value,
    });
  },
  KeyMobile(e) {
    this.setData({
      mobile: e.detail.value,
    });
  },

  getOffline(e) {
    let { pay_type_list, express_price: express, address, express_price_1: express_1, payment, options, isMulti, order_info = [] } = this.data;
    let offline = Number(e.currentTarget.dataset.index);
    // offline !== this.data.offline && this.setData({ payment: -1 });  // 清空支付方式
    
    if (offline === 1) {
      this.setData({
        offline: 1,
        express_price: 0,
        express_price_1: express,
      });
    } else if (offline === 3) {
      this.setData({
        offline: 3,
        express_price: express_1,
      });
      // 切换到同城配送时，重新请求订单数据。
      address && address.id && this.getOrderData(options);
    } else {
      this.setData({
        offline: 0,
        express_price: express_1,
      });
    }
    // 切换物流方式时处理支付方式
    let new_pay_type_list = app.getPayTypeList(pay_type_list, offline, order_info, isMulti);
    ((offline !== 1 && payment === 6) || (offline === 1 && payment === 2)) && (payment = new_pay_type_list && new_pay_type_list[0].payment); // 清空支付方式
    this.setData({
      offlineClick: true,
      new_pay_type_list,
      payment,
      indexNum: app.getpayment(new_pay_type_list, payment),
    });
    
    this.getPrice();
  },

  dingwei(e) {
    let that = this;
    let hit = e && e.currentTarget.dataset.flag;
    wx.getSetting({
      success(res) {
        if (typeof res.authSetting['scope.userLocation'] === 'undefined') {
          wx.getLocation({
            type: 'wgs84',
            altitude: false,
            success: res => {
              that.getShopLists(res.longitude, res.latitude);
            },
          });
        } else if (res.authSetting['scope.userLocation'] === false) {
          that.setData({
            open_setting: true,
          });
        } else {
          if (hit) {
            // 点击了手动定位
            wx.chooseLocation({
              success: function(res) {
                that.setData({
                  location: res.address,
                });
                that.getShopLists(res.longitude, res.latitude);
              },
            });
          } else {
            wx.getLocation({
              type: 'wgs84',
              altitude: false,
              success: res => {
                that.getShopLists(res.longitude, res.latitude);
              },
            });
          }
        }
      },
    });
  },

  getShopLists(longitude, latitude) {
    let that = this;
    app.ws_micro_shoprequest({
      url: api.order.shop_list,
      data: {
        longitude,
        latitude,
        goods_id_str: that.data.cart_id_list ? that.data.cart_id_list.join(',') : that.data.goods_info && that.data.goods_info.goods_id + '',
        goods_type: ''
      },
      success: function(res) {
        if (res.code === 0) {
          that.setData({
            shop_list: res.data,
          });
        }
      },
    });
  },

  orderSubmit(e) {
    let that = this;
    let offline = Number(that.data.offline);
    // let dispatch_type = Number(that.data.dispatch_type);
    let data = {};
    data.form_id = e.detail.formId;
    let {
      isMulti,
      isSingle,
      order_info = [],
      pickedCardCoupon = {},
      payment,
      btnFreezen,
      requireVerify,
    } = this.data;

    // if (btnFreezen) {
    //   return false;
    // }
    that.setData({
      btnFreezen: true,
    })

    // 多店
    isMulti &&
      order_info.forEach(v => {
        v.shop_id = v.is_shop.id;
      });

    // 物流信息校验
    !isMulti && (data.offline = offline);
    let offlinMulti = [];
    isMulti && (offlinMulti = order_info.map(item => Number(item.offline)));
    if (!isMulti) {
      if (offline === 0) {
        if (!that.data.address || !that.data.address.id) {
          wx.showToast({
            title: '请选择收货地址',
            icon: 'none',
          });
          that.setData({
            btnFreezen: false,
          })
          return;
        }
        data.address_id = that.data.address.id;
      } else if (offline === 3) {
        if (!that.data.address || !that.data.address.id) {
          wx.showToast({
            title: '请选择收货地址',
            icon: 'none',
          });
          that.setData({
            btnFreezen: false,
          })
          return;
        }
        data.address_id = that.data.address.id;
        // if (!that.data.shop || !that.data.shop.id) {
        //   wx.showToast({
        //     title: '请选择同城配送的门店',
        //     icon: 'none',
        //   });
        //   return;
        // }
        // data.shop_id = that.data.shop.id;
      }
    } else {
      // 多店校验
      if (offlinMulti.some(i => i === 0 || i === 3)) {
        if (!that.data.address || !that.data.address.id) {
          wx.showToast({
            title: '请选择收货地址',
            icon: 'none',
          });
          that.setData({
            btnFreezen: false,
          })
          return;
        }

        // 同城 超范围 提示
        if (order_info.some(v => Number(v.code) === 3 && Number(v.offline) != 1)) {
          that.setData({
            btnFreezen: false,
          })
          return wx.showToast({
            title: order_info.find(v => Number(v.code) === 3).msg,
            icon: 'none',
          });
        }
      }
      data.address_id =
        that.data.address && that.data.address.id ? that.data.address.id : '';
    }
    // 自提
    if (
      (!isMulti && offline === 1) ||
      (isMulti && offlinMulti.some(i => i === 1))
    ) {
     
      // 多店 自提联系人和电话 展示方式跟 单店一致 20200106 cd
      if (requireVerify != 2) {
        data.address_name = that.data.name;
        data.address_mobile = that.data.mobile;
      }
      if (isSingle && !that.data.shop_list_length) {
        wx.showToast({
          title: '您购买的商品没有合适的自提站点',
          icon: 'none',
        });
        that.setData({
          btnFreezen: false,
        })
        return;
      }


      if (!isMulti && that.data.shop && that.data.shop.id) {
        data.shop_id = that.data.shop.id;
      } else if (!isMulti && !that.data.shop) {
        wx.showToast({
          title: '请选择自提站点',
          icon: 'none',
        });
        that.setData({
          btnFreezen: false,
        })
        return;
      }

      if (Number(requireVerify) === 1) {
  
        if (!data.address_name) {
          wx.showToast({
            title: '请填写收货人',
            icon: 'none',
          });
          that.setData({
            btnFreezen: false,
          })
          return;
        }

        if (!data.address_mobile) {
          wx.showToast({
            title: '请填写联系方式',
            icon: 'none',
          });
          that.setData({
            btnFreezen: false,
          })
          return;
        } else {
          if (Number(that.data.checkmobile) === 1) {
          if (that.data.currency === 'CNY') {
            let check_mobile = app.util.phoneExp.mobile;
            let check_phone = app.util.phoneExp.landline;
            if (
              !check_mobile.test(data.address_mobile) &&
              !check_phone.test(that.data.mobile)
            ) {
                wx.showToast({
                  title: '联系电话格式不正确',
                  icon: 'none',
              });
              that.setData({
                btnFreezen: false,
              })
              return;
            }
          } else {
            let check_canade = app.util.phoneExp.canadaPhone;
            if (!check_canade.test(data.address_mobile)) {
                wx.showToast({
                  title: '联系电话格式不正确',
                  icon: 'none',
              });
              that.setData({
                btnFreezen: false,
              })
              return;
            }
          }
        }
      }
        
      }
    }

    if (payment === -1) {
      that.setData({
        btnFreezen: false,
      })
      return wx.showToast({
        title: '请选择支付方式',
        icon: 'none',
      });
    }

    // 处理商品需求表单
    let form = that.data.form;
    let formList = isMulti ? order_info.map(v => v.form.list) : [form.list];
    let needCheck =
      (isMulti && order_info.some(v => Number(v.form.is_form) === 1)) ||
      (!isMulti && Number(form.is_form) === 1);
    if (needCheck) {
      // const checkeForm = (form_list) => {
      for (let j in formList) {
        let form_list = formList[j];
        for (let i in form_list) {
          if ({}.hasOwnProperty.call(form_list, i)) {
            if (form_list[i].type === 'date') {
              form_list[i].default = form_list[i].default
                ? form_list[i].default
                : that.data.time;
            }
            if (form_list[i].type === 'time') {
              form_list[i].default = form_list[i].default
                ? form_list[i].default
                : '00:00';
            }
            if (form_list[i].type === 'number' && form_list[i].default) {
              let r = /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/;
              if (!r.test(form_list[i].default)) {
                wx.showToast({
                  title: form_list[i].name + '请输入整数',
                  icon: 'none',
                });
                that.setData({
                  btnFreezen: false,
                })
                return;
              }
            }
            if (Number(form_list[i].required) === 1) {
              if (
                form_list[i].type === 'radio' ||
                form_list[i].type === 'checkbox'
              ) {
                let is_true = false;
                for (let j in form_list[i].default_list) {
                  if (Number(form_list[i].default_list[j].is_selected) === 1) {
                    is_true = true;
                  }
                }
                if (!is_true) {
                  wx.showModal({
                    title: '提示',
                    content: '加‘*’的为必填项',
                    showCancel: false,
                  });
                  that.setData({
                    btnFreezen: false,
                  })
                  return;
                }
              } else {
                if (!form_list[i].default) {
                  wx.showModal({
                    title: '提示',
                    content: '加‘*’的为必填项',
                    showCancel: false,
                  });
                  that.setData({
                    btnFreezen: false,
                  })
                  return;
                }
              }
            }
          }
        }
      }

      // };
      // formList.forEach(checkeForm);  //forEach中return不能退出循环
    }
    !isMulti && (data.form = JSON.stringify(form));

    if (!isMulti && that.data.cart_id_list) {
      data.cart_id_list = JSON.stringify(that.data.cart_id_list);
    }
    if (!isMulti && that.data.goods_info) {
      data.goods_info = JSON.stringify(that.data.goods_info);
    }
    if (!isMulti && that.data.picker_coupon) {
      data.user_coupon_id = that.data.picker_coupon.user_coupon_id;
    }
    if (that.data.card_distinguish) {
      let cardno = that.data.IDcardNo;
      if (
        /^(([1][1-5])|([2][1-3])|([3][1-7])|([4][1-6])|([5][0-4])|([6][1-5])|([7][1])|([8][1-2]))\d{4}(([1][9]\d{2})|([2]\d{3}))(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1]))\d{3}[0-9xX]$/.test(
          cardno
        )
      ) {
        data.id_number = cardno;
      } else {
        wx.showModal({
          title: '提示',
          content: '请输入有效的身份证号码',
          showCancel: false,
        });
        that.setData({
          btnFreezen: false,
        })
        return;
      }
    }

    if (that.data.wheel_id_list) {
      data.wheel_id = that.data.wheel_id_list;
      data.credit_total = that.data.picker_wheel.credit;
    }
    if (!isMulti && that.data.content) {
      data.content = that.data.content;
    }
    if (!isMulti && that.data.cart_list) {
      data.cart_list = JSON.stringify(that.data.cart_list);
    }
    if (!isMulti && that.data.estimated_msg && offline != 1) {
      data.estimated_date = that.data.estimated_data.estimated_date;
    }
    if (!isMulti && Number(that.data.integral_radio) === 1) {
      data.use_integral = 1;
      data.use_forehead = that.data.integral.forehead;
    } else if (!isMulti && Number(that.data.integral_radio) !== 1) {
      data.use_integral = 2;
    }
    data.payment = Number(payment);

    if (isMulti && that.data.picker_coupon) {
      for (let index in that.data.picker_coupon) {
        for (let num in order_info) {
          if (
            order_info[num].is_shop &&
            order_info[num].is_shop['id'] ===
              that.data.picker_coupon[index].shop_id
          ) {
            order_info[num]['user_coupon_id'] =
              that.data.picker_coupon[index]['user_coupon_id'];
          }
        }
      }
    }
    isMulti && (data.info = JSON.stringify(order_info));
    data.card_coupon_id =
      pickedCardCoupon && pickedCardCoupon.user_coupon_id
        ? pickedCardCoupon.user_coupon_id
        : 0;
    data.integral_rule_check = that.data.integral_rule_check;

    data.self_mention_date = 0;
    data.self_mention_time = '';

    if (!isMulti && that.data.mentioned_data) {
      let {
        mentionedArray,
        mentionedIdx,
        timeSplice,
      } = that.data.mentioned_data;
      data.self_mention_date =
        timeSplice.length > 0 ? mentionedIdx[0] : mentionedIdx[0] + 1;
      data.self_mention_time =
        that.data.offline == 1 ? mentionedArray[1][mentionedIdx[1]] : '';
    }
    app.getSubscribeMessage(0).then(response => {
    wx.showLoading({
      title: '正在提交',
      mask: true,
    });
    that.sendRequest(data, e);
    });
  },
  getSource(goods_id_list, data, goods_id, isMulti) {
    let hasGoods = false;
    goods_id = Number(goods_id);
    if (goods_id_list) {
      hasGoods = goods_id && goods_id_list.includes(goods_id);
    } else {
      hasGoods = (goods_id === Number(isMulti ? JSON.parse(data.info)[0].goods_info.goods_id : JSON.parse(data.goods_info).goods_id))
    }
    return hasGoods;
  },

  sendRequest(data, e) {
    let that = this;
    let { isMulti, order_info = [], version_type, goods_id_list } = this.data;
    let { last_share_guide_id, last_share_good_id, last_room_id, last_room_good_id } = app.ws_micro_shop_globalData;
    if (version_type === '1' || version_type === '3') {
      if (last_share_guide_id && that.getSource(goods_id_list, data, last_share_good_id, isMulti)) {
        data.staff_id = last_share_guide_id;
        data.staff_gid = last_share_good_id;
      }
    }
    if (last_room_id && that.getSource(goods_id_list, data, last_room_good_id, isMulti)) {
      data.room_id = last_room_id;
    }
    // that.setData({
    //   btnFreezen: true,
    // });
    let goods_card_list = isMulti
      ? order_info
        .map(v => v.goods_card_list)
        .reduce((a, b) => [...a, ...b], [])
      : this.data.goods_card_list;
    app.ws_micro_shoprequest({
      url: api.order.submitNew, // 新接口
      method: 'POST',
      data: data,
      success: function(res) {
        if (res.code === 0) {
          wx.hideLoading();
          setTimeout(function() {
            that.setData({
              options: {},
            });
          }, 1);
          if (Number(res.data.pay_price) <= 0) {
            that.chooseJumpTo();
            return;
          }
          let order_id = res.data.order_id;
          if (data.payment === 0) {
            app.ws_micro_shoprequest({
              url: api.order.payDataNew, // 新接口
              data: {
                order_id: order_id,
                pay_type: 'WECHAT_PAY',
              },
              success: function(res) {
                if (res.code === 0) {
                  wx.requestPayment({
                    timeStamp: res.data.timeStamp,
                    nonceStr: res.data.nonceStr,
                    package: res.data.package,
                    signType: res.data.signType,
                    paySign: res.data.paySign,
                    complete: function(e) {
                      if (
                        e.errMsg === 'requestPayment:fail' ||
                        e.errMsg === 'requestPayment:fail cancel'
                      ) {
                        wx.showModal({
                          title: '提示',
                          content: '订单尚未支付',
                          showCancel: false,
                          confirmText: '确认',
                          success: function(res) {
                            if (res.confirm) {
                              app.util.navigateTo(
                                '/ws_micro_shop/pages/order/order',
                                { status: 0 },
                                true
                              );
                            }
                          },
                        });
                        return;
                      }
                      if (e.errMsg === 'requestPayment:ok') {
                        // 支付成功之后再调一次接口用来派单 jane 0212
                        app.ws_micro_shoprequest({
                          url: api.order.payDataNew,
                          data: {
                            order_id: order_id,
                            pay_type: 'WECHAT_PAY',
                            distributeRider: 1,
                          },
                          success: function(res) {},
                        });
                        if (goods_card_list.length > 0) {
                          that.setData({
                            goods_card_list,
                            show_card: true,
                            btnFreezen: false,
                          });
                        } else {
                          that.chooseJumpTo();
                          // app.util.navigateTo(
                          //   '/ws_micro_shop/pages/order/order',
                          //   { status: 1 },
                          //   true
                          // );
                        }
                        return;
                      }
                      app.util.navigateTo(
                        '/ws_micro_shop/pages/order/order',
                        { status: -1 },
                        true
                      );
                    },
                  });
                  let quick_list = wx.getStorageSync('quick_list');
                  if (quick_list) {
                    let length = quick_list.length;
                    for (let i = 0; i < length; i++) {
                      let goods = quick_list[i]['goods'];
                      let length2 = goods.length;
                      for (let a = 0; a < length2; a++) {
                        goods[a]['num'] = 0;
                      }
                    }
                    wx.setStorageSync('quick_lists', quick_list);
                    let carGoods = wx.getStorageSync('carGoods');
                    length = carGoods.length;
                    for (let i = 0; i < length; i++) {
                      carGoods[i]['num'] = 0;
                      carGoods[i]['goods_price'] = 0;
                      that.setData({
                        carGoods: carGoods,
                      });
                    }
                    wx.setStorageSync('carGoods', carGoods);
                    let total = wx.getStorageSync('total');
                    if (total) {
                      total.total_num = 0;
                      total.total_price = 0;
                      wx.setStorageSync('total', total);
                    }
                    let check_num = wx.getStorageSync('check_num');
                    check_num = 0;
                    wx.setStorageSync('check_num', check_num);
                    let quick_hot_goods_lists = wx.getStorageSync(
                      'quick_hot_goods_lists'
                    );
                    length = quick_hot_goods_lists.length;
                    for (let i = 0; i < length; i++) {
                      quick_hot_goods_lists[i]['num'] = 0;
                      that.setData({
                        quick_hot_goods_lists: quick_hot_goods_lists,
                      });
                    }
                    wx.setStorageSync(
                      'quick_hot_goods_lists',
                      quick_hot_goods_lists
                    );
                  }
                  return;
                }
                if (res.code === 1) {
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                  });
                  setTimeout(function () {
                    app.util.navigateTo(
                      '/ws_micro_shop/pages/order/order',
                      { status: 0 },
                      true
                    );
                  }, 1000);
                  return;
                }
              },
            });
          }
          if (data.payment === 2) {
            app.ws_micro_shoprequest({
              url: api.order.payDataNew,
              data: {
                order_id: order_id,
                pay_type: 'HUODAO_PAY',
                form_id: e.detail.formId,
              },
              success: function(res) {
                if (res.code === 0) {
                  that.chooseJumpTo();
                  // app.util.navigateTo(
                  //   '/ws_micro_shop/pages/order/order',
                  //   { status: 1 },
                  //   true
                  // );
                } else {
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                  });
                  setTimeout(function () {
                    app.util.navigateTo(
                      '/ws_micro_shop/pages/order/order',
                      { status: 0 },
                      true
                    );
                  }, 1000);
                  return;
                }
              },
            });
          }
          if (data.payment === 3) {
            app.ws_micro_shoprequest({
              url: api.order.payDataNew,
              data: {
                order_id: order_id,
                pay_type: 'BALANCE_PAY', // 两个以上的门店，禁用余额支付。
                form_id: e.detail.formId,
              },
              success: function(res) {
                if (res.code === 0) {
                  if (goods_card_list.length > 0) {
                    that.setData({
                      goods_card_list,
                      show_card: true,
                      btnFreezen: false,
                    });
                  } else {
                    that.chooseJumpTo();
                    // app.util.navigateTo(
                    //   '/ws_micro_shop/pages/order/order',
                    //   { status: 1 },
                    //   true
                    // );
                  }
                } else {
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                  });
                  setTimeout(function() {
                    app.util.navigateTo(
                      '/ws_micro_shop/pages/order/order',
                      { status: 0 },
                      true
                    );
                  }, 1000);
                  return;
                }
              },
            });
          }
          if (data.payment === 5) {
            app.ws_micro_shoprequest({
              url: api.order.payDataNew,
              data: {
                order_id: order_id,
                pay_type: 'CARD_PAY',
                form_id: e.detail.formId,
              },
              success: function(res) {
                if (res.code === 0) {
                  if (goods_card_list.length > 0) {
                    that.setData({
                      goods_card_list,
                      show_card: true,
                      btnFreezen: false,
                    });
                  } else {
                    that.chooseJumpTo();
                    // app.util.navigateTo(
                    //   '/ws_micro_shop/pages/order/order',
                    //   { status: 1 },
                    //   true
                    // );
                  }
                } else {
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                  });
                  setTimeout(function() {
                    app.util.navigateTo(
                      '/ws_micro_shop/pages/order/order',
                      { status: 0 },
                      true
                    );
                  }, 1000);
                  return;
                }
              },
            });
          }
          if (data.payment === 6) {
            app.ws_micro_shoprequest({
              url: api.order.payDataNew,
              data: {
                order_id: order_id,
                pay_type: 'CLERK_PAY',
                form_id: e.detail.formId,
              },
              success: function(res) {
                if (res.code === 0) {
                  that.chooseJumpTo();
                  // app.util.navigateTo(
                  //   '/ws_micro_shop/pages/order/order',
                  //   { status: 1 },
                  //   true
                  // );
                } else {
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                  });
                  setTimeout(function () {
                    app.util.navigateTo(
                      '/ws_micro_shop/pages/order/order',
                      { status: 0 },
                      true
                    );
                  }, 1000);
                  return;
                }
              },
            });
          }
        }
        if (res.code === 1) {
          wx.hideLoading();
          that.setData({
            btnFreezen: false,
          });
          wx.showToast({
            title: res.msg,
            icon: 'none',
          });
          return;
        }
        if (res.code === 2) {
          wx.hideLoading();
          wx.showModal({
            title: '提示',
            content:
              '由于您参与了优惠活动（满减、优惠券、积分抵扣、会员折扣等商城里的优惠活动）,购买商品后无法获得积分,确定购买吗',
            success(res) {
              if (res.confirm) {
                that.setData({
                  integral_rule_check: 2,
                });
                that.setData({
                  btnFreezen: false,
                });
                that.orderSubmit(e);
              } else if (res.cancel) {
                that.setData({
                  btnFreezen: false,
                });
                return;
              }
            },
          });
          return;
        }
      },
    });
  },
  chooseJumpTo() {
    wx.showModal({
      content: '支付成功',
      cancelText: '返回首页',
      confirmText: '订单列表',
      success: function(resp) {
        if (resp.confirm) {
          app.util.navigateTo(
            '/ws_micro_shop/pages/order/order',
            { status: 1 },
            true
          );
        }else if (resp.cancel) {
          app.util.navigateTo(
            '/ws_micro_shop/pages/index/index'
          );
        }
      }
    })
  },

  getOrderData(options) {
    let that = this;
    let num = that.data.num + 1;
    let callCount = that.data.callCount + 1;
    that.setData({
      num,
      callCount,
    });
    let data = {};
    let address_id = '';
    let shop_id = '';
    if (that.data.address && that.data.address.id) {
      address_id = that.data.address.id;
    }
    data.address_id = address_id;
    data.pay_type = that.data.paytype;
    if (that.data.shop && that.data.shop.id) {
      shop_id = that.data.shop.id;
    }
    data.shop_id = shop_id;
    wx.showLoading({
      title: '正在加载',
      mask: true,
    });
    if (options.cart_list) {
      data.cart_list = options.cart_list;
    }

    if (options.cart_id_list) {
      let cart_id_list = JSON.parse(decodeURIComponent(options.cart_id_list));
      data.cart_id_list = cart_id_list;
    }
    
    if (options.goods_info) {
      data.goods_info = options.goods_info;
    }

    let { goods_info = '' } = this.data;
    goods_info = JSON.stringify(goods_info);
    let matchGoods = goods_info && JSON.parse(goods_info).matchGoods;
    Array.isArray(matchGoods) &&
      matchGoods.length > 0 &&
      (data.matchGoods = matchGoods);
    // 获取订单预览信息
    app.ws_micro_shoprequest({
      url: api.order.submitPreviewNew,
      data: data,
      success: function(res) {
        wx.hideLoading();
        if (res.code === 0 || res.code === 3) {
          // 如果send_type = 2 直接设置仅自提 cd

          that.setData({
            total_price3: res.data.total_price2,
            requireVerify: res.data.require_verify,
          });

          if (that.data.isMulti) {
            let order_info = res.data.order_info;
            if (order_info[0].code && order_info[0].code === 1) {
              wx.showModal({
                title: '提示',
                content: order_info[0].msg,
                showCancel: false,
                confirmText: '确定',
                success: function(resp) {
                  if (resp.confirm) {
                    wx.navigateBack({
                      delta: 1,
                    });
                  }
                },
              });
            }
            let orderInfo = that.data.order_info;

            // 计算购买返积分 之 合 jane
            for (let i = 0; i < order_info.length; i++) {
              order_info[i].integralTotal = order_info[i].list.reduce((a, b) => a + Number(b.give), 0);
            }

            let couponsByStore = that.data.couponsByStore || [];

            if (callCount === 2) {
              for (let i = 0; i < order_info.length; i++) {
                  order_info[i].user_coupon_id = order_info[i].coupon_list[0] ? order_info[i].coupon_list[0].user_coupon_id : '';
                }

              couponsByStore = Array.from({ length: order_info.length }, (v, i) => ({
                shop: order_info[i].is_shop.id,
                userCouponId: order_info[i].coupon_list[0] ? res.data.order_info[i].coupon_list[0].user_coupon_id : '',
                subPrice: order_info[i].coupon_list[0] ? res.data.order_info[i].coupon_list[0].sub_price : 0,
              }));
              let total = couponsByStore.reduce((a, b) => a + Number(b.subPrice), 0);
              res.data.total_price2 = res.data.total_price2 - total;

              that.setData({
                couponsByStore,
                totalSubPrice: total,
                couponPrice: Number(res.data.total_price2),
                show_coupon_picker: false,
              });
              that.calculateIntegralForehead(Number(res.data.total_price2)); // 取消普通优惠券 计算积分抵扣
            }

            if (callCount > 2) {

              for (let i = 0; i < order_info.length; i++) {

                if (order_info[i].coupon_list && order_info[i].coupon_list.length > 0) {
                  let index = order_info[i].coupon_list.findIndex(item => Number(item.user_coupon_id) === Number(orderInfo[i].user_coupon_id));
                  if (index >= 0) {
                  order_info[i].user_coupon_id = orderInfo[i].user_coupon_id;
                    res.data.total_price2 = that.data.total_price3 - that.data.totalSubPrice;
                } else {
                    order_info[i].user_coupon_id = '';

                    that.setData({
                      [`couponsByStore[${i}].userCouponId`]: '',
                      [`couponsByStore[${i}].subPrice`]: 0,
                      couponPrice: res.data.total_price2,
                    }, () => {
                      let totalSubPrice = that.data.couponsByStore.reduce((a, b) => a + Number(b.subPrice), 0);
                      that.setData({ totalSubPrice });
                      that.calculateIntegralForehead(Number(res.data.total_price2)); // 取消普通优惠券 计算积分抵扣
                    });

                }
                }

              }
  
            }

            let isInitTime = true;
            // 配送方式默认选择第一个
            for (let i = 0; i < order_info.length; i++) {
              if (order_info[i].estimated_msg) {
                // 处理选择送达时间
                let estimated_data = that.getTime(
                  order_info[i].estimated_day,
                  order_info[i].estimated_timeBetween,
                  order_info[i].estimated_msg
                );
                order_info[i].estimated_data = estimated_data;
                order_info[i].estimated_date = estimated_data.estimated_date;
              }

              if (
                res.data.self_mention_date &&
                res.data.self_mention_date.length > 0 &&
                order_info[i].self_mention_time
              ) {
                // duo店处理 自提时间段  self_mention_time
                let smt = order_info[i].self_mention_time || [];
                let timeSplice = [];
                for (let m = 0; m < smt.length; m++) {
                  that.timeRange(smt[m]) && timeSplice.push(smt[m]);
                }

                if (
                  orderInfo &&
                  orderInfo[i] &&
                  orderInfo[i].mentioned_data &&
                  orderInfo[i].mentioned_data.mentionedIdx
                ) {
                  if (
                    orderInfo[i].mentioned_data.mentionedIdx[0] == 0 &&
                    orderInfo[i].mentioned_data.mentionedIdx[1] == 0
                  ) {
                    isInitTime = true;
                  } else {
                    isInitTime = false;
                  }
                }

                if (isInitTime) {
                  order_info[i].mentioned_data = {
                    dataItem:
                      timeSplice.length === 0
                        ? res.data.self_mention_date.splice(0, 1)
                        : res.data.self_mention_date,
                    timeItem: order_info[i].self_mention_time,
                    mentionedArray:
                      timeSplice.length === 0
                        ? [
                          res.data.self_mention_date,
                          order_info[i].self_mention_time,
                        ]
                        : [res.data.self_mention_date, timeSplice],
                    mentionedIdx: [0, 0],
                    timeSplice: timeSplice,
                  };

                  order_info[i].self_mention_date =
                    timeSplice.length > 0 ? 0 : 1;
                  order_info[i].self_mention_time =
                    timeSplice.length === 0
                      ? order_info[i].self_mention_time[0]
                      : timeSplice[0];

                } else {
                  order_info[i].mentioned_data = orderInfo[i].mentioned_data;
                  order_info[i].self_mention_date =
                    orderInfo[i].self_mention_date;
                  order_info[i].self_mention_time =
                    orderInfo[i].self_mention_time;
                }
              }

              let isRider = order_info[0] && order_info[0].is_shop && order_info[0].is_shop.isopenrider ? Number(order_info[0].is_shop.isopenrider) : 0;

              if (orderInfo && orderInfo.length > 0) {
                // 支付方式切换后不重置物流方式
                order_info[i].transportType = isRider === 1 ? '骑手配送' : orderInfo[i].transportType;
                order_info[i].offline = orderInfo[i].offline;
                order_info[i].showExpressPrice = orderInfo[i].showExpressPrice;
              } else {
                if (order_info[i].send_type === 2) {
                  order_info[i].transportType = '到店自提';
                  order_info[i].offline = 1;
                  order_info[i].showExpressPrice = false;
                } else {
                  // 同城配送有 系统 和 门店设置，以门店为准 cd
                  // 处理一下 骑手 配送方式 ： 骑手只有自提和骑手配送  jane
                  order_info[i].transportType = isRider === 1 ? '骑手配送' : Number(order_info[i].is_shop.dispatch_type) === 1 ? '同城配送' : '快递送货';
                  order_info[i].offline = Number(order_info[i].is_shop.dispatch_type) === 1 ? 3 : 0;
                  order_info[i].showExpressPrice = true;
                }
              }
            }

            // 判断order_info长度为1的情况下设置offline的值，对应paytype.wxml中支付方式的判断
            if (order_info && order_info.length === 1) {
              that.setData({
                offline: order_info[0].offline,
              });
            }
          } else{

            if (callCount === 2) {
              let total = res.data.coupon_list[0] ? res.data.coupon_list[0].sub_price : 0;
              res.data.total_price2 = res.data.total_price2 - total;
            that.setData({
              picker_coupon: res.data.coupon_list && res.data.coupon_list[0] || '',
              couponPrice: Number(res.data.total_price2),
              show_coupon_picker: false,
            });

            that.calculateIntegralForehead(Number(res.data.total_price2)); // 取消普通优惠券 计算积分抵扣
          }

            if (callCount > 2) {
              // 判断当前的优惠券在不在接口返回中  jane

              if (res.data.coupon_list && res.data.coupon_list.length > 0 && that.data.picker_coupon) {
                let index = res.data.coupon_list.findIndex(item => Number(item.user_coupon_id) === Number(that.data.picker_coupon.user_coupon_id));
                if (index >= 0) {
                  res.data.total_price2 = that.data.total_price3 - that.data.picker_coupon.sub_price;
                } else {
                  // 清空优惠券
                  that.setData({
                    picker_coupon: false,
                    couponPrice: Number(res.data.total_price2),
                    show_coupon_picker: false,
                  });
      
                  that.calculateIntegralForehead(Number(res.data.total_price2)); // 取消普通优惠券 计算积分抵扣
                }
          }

            }
          }

          // 多店 不要重置 form表单内容
          let formNull = true;
          if (that.data.isMulti && that.data.order_info) {
            let formArr = that.data.order_info;
            for (let i = 0; i < formArr.length; i++) {
              if (formArr[i].form && formArr[i].list.length > 0) {
                formNull = formArr[i].form.list.every(function(item) {
                  return item.default == '' && item.type !== 'uploadimg';
                });
              }
            }
            if (!formNull) {
              // 多店 将data中的form 赋值给res中的data
              let dataForm = that.data.order_info;
              let resForm = res.data.order_info;

              for (let i = 0; i < dataForm.length; i++) {
                resForm[i].form = dataForm[i].form;
                if (callCount <= 2) {//处理多店时form表单不被重置的问题
                  let form_list = resForm[i].form.list;
                  for (let key in form_list) {
                    if (Object.prototype.hasOwnProperty.call(form_list, key)) {
                      let item = form_list[key];
                      if (item.type === 'uploadimg') {
                        resForm[i].form.list[key].imagesCount = resForm[i].form.list[key].default;
                        item.imagesCount = item.default;
                        resForm[i].form.list[key].default = "";
                      }
                    }
                  }
                }
              }
              
            }
          }

          that.data.isMulti &&
            that.setData(
              {
                ...res.data,
                couponPrice: res.data.total_price2 || '',
                name: callCount > 2 ? that.data.name : (res.data.address ? res.data.address.name : ''),
                mobile: callCount > 2 ? that.data.mobile : (res.data.address ? res.data.address.mobile : ''),
                isRider: res.data.order_info[0] && res.data.order_info[0].is_shop && Number(res.data.order_info[0].is_shop.isopenrider) === 1 ? Number(res.data.order_info[0].is_shop.isopenrider) : 0,
              },
              () => {
                // 处理支付方式展示数据
                let { pay_type_list, offline, order_info, isMulti } = that.data;
                that.setData({
                  pay_type_list,
                  new_pay_type_list: app.getPayTypeList(pay_type_list, offline, order_info, isMulti),
                });
                that.getPrice();
              }
            ); // 多店
          that.data.isMulti || that.getSingleShopData(res); // 单店
          // 支付方式默认选择第一个
          if (
            that.data.num === 1 &&
            that.data.pay_type_list &&
            Object.keys(that.data.pay_type_list).length > 0
          ) {
            that.setData({
              payment:
                that.data.pay_type_list[0].payment === 6 &&
                that.data.offline !== 1
                  ? -1
                  : that.data.pay_type_list[0].payment,
            });
            that.payFirst();
          }
        }
        if (res.code === 1) {
          wx.showModal({
            title: '提示',
            content: res.msg,
            showCancel: false,
            confirmText: '确定',
            success: function(resp) {
              if (resp.confirm) {
                wx.navigateBack({
                  delta: 1,
                });
              }
            },
          });
        } else if (res.code === 3 && Number(that.data.offline) === 3) {
          // 同城配送超出限制
          that.setData({
            express_price: res.msg,
            delivery_rule: false,
          });
          callCount >= 2 && wx.showModal({
            title: '提示',
            content: res.msg,
            showCancel: false,
            confirmText: '确定',
          });
        } else if (res.code === 2) {
          wx.showModal({
            title: '友情提示',
            content: '当前收货地址缺失经纬度，请重新编辑',
            showCancel: false,
            success: function(resp) {
              if (resp.confirm) {
                app.util.navigateTo(
                  'ws_micro_shop/pages/address-edit/address-edit',
                  {
                    id: res.data.address_id,
                    address_switch: res.data.address_switch,
                  },
                  false
                );
              }
            },
          });
        }
      },
    });
  },

  getSingleShopData(res) {
    const that = this;
    let shop_list = res.data.shop_list || [];
    let retailStore = {};
    shop_list && shop_list.length === 1 && (retailStore = shop_list[0]);
    res.data.is_shop && (retailStore = res.data.is_shop);

    if (res.data.is_shop) {
      that.setData({
        shop: res.data.is_shop, // 如果后端设置了默认地址 is_shop
      });
    } else {
      that.setData({
        shop: false,
      });
    }

    let {
      total_price = '',
      total_price2 = '',
      list: goods_list = '',
      address = '',
      cart_list,
      estimated_msg,
      estimated_day,
      coupon_list,
      wheel_list = [],
      card,
      card_discount,
      card_distinguish,
      dispatch_type,
      estimated_timeBetween,
      send_type,
      level,
      userinfo,
      integral,
      goods_card_list = '',
      form,
      pay_type_list = [],
      is_payment,
      is_overlay = '',
      gst_rate = 0,
      pst_rate = 0,
      card_coupon_list,
      goods_info,
      cart_id_list,
      promotion,
    } = res.data;
    let { offline, order_info, isMulti } = that.data;

    let new_pay_type_list = app.getPayTypeList(pay_type_list, offline, order_info, isMulti);

    // 计算购买返积分 之 合 jane
    for (let i = 0; i < res.data.list.length; i++) {
      res.data.integralTotal = res.data.list.reduce((a, b) => a + Number(b.give), 0);
    }

    let formNull = true;
    
    if (that.data.form && that.data.form.list) {
      let formArr = that.data.form.list;
      formNull = formArr.every(function(item) {
        return item.default === '';
      });
    }

    let dataObj = {
      total_price,
      total_price2,
      couponPrice: total_price2,
      goods_list,
      address,
      coupon_list,
      wheel_list,
      shop_list_length: shop_list.length,
      retailStore,
      card,
      card_discount,
      card_distinguish,
      dispatch_type,
      send_type,
      level,
      userinfo,
      new_total_price: total_price2,
      default_integral: JSON.stringify(integral),
      integral,
      goods_card_list,
      is_payment,
      pay_type_list,
      is_overlay,
      gst_rate,
      pst_rate,
      card_coupon_list,
      promotion,
      is_shop: res.data.is_shop,
      delivery_rule: res.data.delivery_rule,
      integralTotal: res.data.integralTotal,
      goods_verify_text: res.data.goods_verify_text
    };

    // 单店处理 自提时间段  self_mention_time
    let isInitTime = true;
    let smt = res.data.self_mention_time;
    let timeSplice = [];
    if (smt) {
      for (let i = 0; i < smt.length; i++) {
        if (that.timeRange(smt[i])) timeSplice.push(smt[i]);
      }

      if (that.data.mentioned_data && that.data.mentioned_data.mentionedIdx) {
        let { mentionedIdx } = that.data.mentioned_data;
        if (Number(mentionedIdx[0]) === 0 && Number(mentionedIdx[1]) === 0) {
          isInitTime = true;
        } else {
          isInitTime = false;
        }
      }
      if (isInitTime) {
        Object.assign(dataObj, {
          mentioned_data: {
            dataItem:
              timeSplice.length === 0
                ? res.data.self_mention_date.splice(0, 1)
                : res.data.self_mention_date,
            timeItem: res.data.self_mention_time,
            mentionedArray:
              timeSplice.length === 0
                ? [res.data.self_mention_date, res.data.self_mention_time]
                : [res.data.self_mention_date, timeSplice],
            mentionedIdx: [0, 0],
            timeSplice: timeSplice,
          },
        });
      }
    }

    if (formNull) {
      Object.assign(dataObj, {
        form,
      });
      let form_list = dataObj.form.list;
      for (let i in form_list) {
        if (Object.prototype.hasOwnProperty.call(form_list, i)) {
          let item = form_list[i];
          if (item.type === 'uploadimg') {
            dataObj.form.list[i].imagesCount = dataObj.form.list[i].default;
            item.imagesCount = item.default;
            dataObj.form.list[i].default = "";
          }
        }
      }
    }

    // 自提联系人 重置问题 cd 20200106
    that.setData(
      Object.assign(dataObj, {
        name: that.data.callCount > 2 ? that.data.name : (res.data.address ? res.data.address.name : ''),
        mobile: that.data.callCount > 2 ? that.data.mobile : (res.data.address ? res.data.address.mobile : ''),
      })
    );

    if (!that.data.chooseAddr && !that.data.chooseShop) {
      that.setData(
        Object.assign(dataObj, {
          express_price: res.data.express_price ? res.data.express_price : 0,
        })
      );
    } else if (that.data.chooseAddr) {
      that.setData({
        goods_list: res.data.goods_list,
        express_price: res.data.express_price ? res.data.express_price : 0,
      });
    } else if (that.data.chooseShop) {
      that.setData(
        Object.assign(dataObj, {
          express_price: res.data.express_price ? res.data.express_price : 0,
        })
      );
    }

    goods_info && that.setData({ goods_info });
    cart_id_list && that.setData({ cart_id_list });
    cart_list && that.setData({ cart_list });
    if (estimated_msg) {
      let { estimated_data: ed, callCount } = that.data;
      let estimated_data = callCount > 2 ? ed :  that.getTime(
        estimated_day,
        estimated_timeBetween,
        estimated_msg
      );
      that.setData({
        estimated_msg,
        estimated_data,
      });
    }

    if (!that.data.offlineClick) {
      if (Number(res.data.dispatch_type) !== 0) {
        if (Number(res.data.send_type) === 2) {
          that.setData({
            offline: 1,
          });
        } else {
          that.setData({
            offline: 3,
          });
        }
      } else {
        if (Number(res.data.send_type) === 2) {
          that.setData({
            offline: 1,
          });
        } else {
          that.setData({
            offline: 0,
          });
        }
      }
    }

    that.setData({
      couponPrice: dataObj.couponPrice,
      delivery_rule: dataObj.delivery_rule,
      pay_type_list,
      new_pay_type_list,
    });

    that.getPrice();
  },

  copyText(e) {
    let text = e.currentTarget.dataset.text;
    if (!text) {
      return;
    }
    wx.setClipboardData({
      data: text,
      success: function() {
        wx.showToast({
          title: '已复制内容',
        });
      },
      fail: function() {
        wx.showToast({
          title: '复制失败',
          icon: 'none',
        });
      },
    });
  },

  showCouponPicker(e) {
    // if (this.data.coupon_list && this.data.coupon_list.length > 0) {
    //   this.setData({
    //     show_coupon_picker: true,
    //   });
    // }
    let { index: idx } = e.currentTarget.dataset;
    let { order_info, isMulti, coupon_list } = this.data;

    this.setData({
      couponPicker: true,
      curCouponArr: isMulti ? order_info[idx].coupon_list : coupon_list,
    });
  },

  showCardCouponPicker() {
    if (this.data.card_coupon_list && this.data.card_coupon_list.length > 0) {
      this.setData({
        show_coupon_picker: true,
        showCardCouponList: true,
      });
    }
  },

  pickCardCoupon(e) {
    let index = e.currentTarget.dataset.index;
    let cardCoupon = this.data.card_coupon_list[index];
    let { showCardCouponList } = this.data;
    if (index === '-1') {
      this.setData({
        showCardCouponList: !showCardCouponList,
        show_coupon_picker: false,
        pickedCardCoupon: {},
      });
    } else {
      this.setData({
        pickedCardCoupon: cardCoupon,
        show_coupon_picker: false,
        showCardCouponList: !this.data.showCardCouponList,
      });
    }
    this.getPrice();
  },

  calculateIntegralForehead({ couponPrice = 0 }) {
    let {
      isMulti,
      integral = {},
      order_info = [],
      couponsByStore: couponChoosed = [],
    } = this.data;
    // 单店
    if (!isMulti && integral) {
      !integral.originalForhead &&
        (integral.originalForhead = Number(integral.forehead));
      if (couponPrice <= integral.originalForhead) {
        integral.forehead = couponPrice;
        integral.forehead_integral = Math.ceil(
          integral.forehead * Number(integral.rate)
        );
      }
      this.setData({ integral });
    }

    // 多店
    let normalCouponReduce = 0;
    let afterReduce = 0;
    isMulti &&
      order_info &&
      order_info.forEach(item => {
        !item.originalForhead &&
          (item.originalForhead = item.integral.forehead);
        normalCouponReduce =
          couponChoosed.length > 0
            ? couponChoosed.find(i => Number(i.shop) === Number(item.is_shop.id)).subPrice
            : 0;
        afterReduce = Number(item.total_price - normalCouponReduce);

        afterReduce <= item.originalForhead &&
          ((item.integral.forehead = afterReduce), true) &&
          ((item.use_forehead = afterReduce), true) &&
          (item.integral.forehead_integral = Math.ceil(
            afterReduce * Number(item.integral.rate)
          ));
      });
    isMulti && this.setData({ order_info });
  },

  pickCoupon(e) {
    let that = this;
    let { index = '', shopId = '', flag = '', userCouponId = '' } = e.currentTarget.dataset;
  
    let total_price2 = Number(this.data.total_price2);
    let couponPrice = total_price2;
    let coupon = [];
    let { isMulti, integral, totalSubPrice = 0, order_info = [], couponsByStore: couponChoosed = [] } = this.data;

    if (Number(that.data.total_price3) !== Number(total_price2)) {
      total_price2 = couponPrice = that.data.total_price3;
    }

    if (String(flag) === 'close') {
      this.setData({
        couponPicker: false,
      });
    }

    if (Number(index) === -1) {
      // 重置优惠券的时候   多店处理 新版优惠券
      if (isMulti) {
        let index = order_info.findIndex(item => Number(item.is_shop.id) === Number(shopId));

        this.setData({
          [`order_info[${index}].user_coupon_id`]: '', 
          [`couponsByStore[${index}].userCouponId`]: '',
          [`couponsByStore[${index}].subPrice`]: 0,
          couponPrice: total_price2,
        }, () => {
          totalSubPrice = this.data.couponsByStore.reduce((a, b) => a + Number(b.subPrice), 0);
          this.setData({ totalSubPrice });
        });

      } else {
        this.setData({
          picker_coupon: false,
          totalSubPrice: '',
          couponPrice: total_price2,
        });
      }

      this.calculateIntegralForehead({ couponPrice }); // 取消普通优惠券 计算积分抵扣

      this.setData({
        // couponPicker: false,
        // integral: isMulti ? orderInfo.map(item => item.integral) : JSON.parse(this.data.default_integral),
      });
    } else {
      isMulti &&
        couponChoosed.length === 0 &&
        wx.showToast({
          title: '至少选择一个优惠券',
          icon: 'none',
        });
      if (isMulti) {
        for (let index in this.data.coupon_list) {
          for (let num in couponChoosed) {
            if (
              couponChoosed[num]['userCouponId'] ==
              this.data.coupon_list[index]['user_coupon_id']
            ) {
              coupon.push(this.data.coupon_list[index]);
            }
          }
        }
      } else {
        let eq = this.data.coupon_list.findIndex(item => Number(item.user_coupon_id) === Number(userCouponId)); 
        coupon = this.data.coupon_list[eq];
      }
      // let integral = JSON.parse(this.data.default_integral);
      if (!isMulti && Number(integral.forehead) > Number(couponPrice)) {
        // 积分折扣金额大于原价 单店
        couponPrice = Number(integral.forehead);
      }

      // 原价扣除优惠券优惠金额
      !isMulti && coupon &&
        (couponPrice = Number(couponPrice - Number(coupon.sub_price)).toFixed(
          2
        ));
      isMulti && (couponPrice -= Number(totalSubPrice));

      // if (!isMulti) {
      //   let rate = Number(integral.rate);
      //   !integral.originalForhead && (integral.originalForhead = Number(integral.forehead));
      //   if (Number(couponPrice) < integral.originalForhead) {
      //     integral.forehead = couponPrice;
      //     integral.forehead_integral = Math.ceil(couponPrice * rate);
      //   }
      // }

      // isMulti && this.calculateIntegralForehead();

      this.setData({
        picker_coupon: coupon,
        integral,
      });

      // 计算积分抵扣
      this.calculateIntegralForehead({ couponPrice });

      // 共用数据
      this.setData({
        couponPrice,
        // couponPicker: false,
      });
    }

    if (this.data.is_overlay === 0) {
      this.setData({
        picker_wheel: false,
        show_wheel_picker: false,
      });
    }
    this.getPrice();
  },

  chooseCoupon(e) {
    let { userCouponId, shopId, subPrice } = e.currentTarget.dataset;
    let { order_info = [], couponsByStore } = this.data;

    let index = couponsByStore.findIndex(item => Number(item.shop) === Number(shopId));

    if (Number(userCouponId) === Number(order_info[index].user_coupon_id)) return false;

    let totalSubPrice = 0;
    index >= 0 &&
      ((couponsByStore[index].userCouponId =
        couponsByStore[index].userCouponId === userCouponId
          ? ''
          : userCouponId),
      true) &&
      ((couponsByStore[index].subPrice = subPrice), true) &&
      (totalSubPrice = couponsByStore.reduce(
        (a, b) => a + Number(b.subPrice),
        0
      ));

    order_info[index].user_coupon_id =
      order_info[index].user_coupon_id === userCouponId ? '' : userCouponId;
    this.setData({ couponsByStore, order_info, totalSubPrice });
  },

  hideCouponPicker() {
    this.setData({
      couponPicker: false,
    });
  },

  disabledClick() {
    return false;
  },

  showWheelPicker() {
    if (this.data.wheel_list && this.data.wheel_list.length > 0) {
      this.setData({
        show_wheel_picker: true,
      });
    }
  },

  pickWheel(e) {
    let index = Number(e.currentTarget.dataset.index);
    if (index === -1) {
      this.setData({
        picker_wheel: false,
        show_wheel_picker: false,
      });
    } else {
      this.setData({
        picker_wheel: this.data.wheel_list[index],
        show_wheel_picker: false,
      });
    }
    this.getPrice();
  },

  pickWheel_list(e) {
    let index = e.currentTarget.dataset.index;
    let wheel_list = this.data.wheel_list;
    if (wheel_list[index].checked) {
      wheel_list[index].checked = false;
    } else {
      wheel_list[index].checked = true;
    }
    this.setData({
      wheel_list: wheel_list,
    });
  },

  pickWheel_submit() {
    let that = this;
    let wheel_list = that.data.wheel_list;
    let total_price2 = that.data.total_price2;
    let wheel_id_list = [];
    for (let i in wheel_list) {
      if (wheel_list[i].checked) {
        wheel_id_list.push(wheel_list[i].id);
      }
    }
    if (wheel_id_list.length === 0) {
      return true;
    }

    app.ws_micro_shoprequest({
      url: api.order.wheel,
      data: {
        wheel_id_list: JSON.stringify(wheel_id_list),
        total_price2: total_price2,
      },
      success: function(res) {
        if (res.erron === -1) {
          wx.showToast({
            title: res.message,
            icon: 'none',
            duration: 3000,
          });
        } else {
          that.setData({
            wheel_id_list: JSON.stringify(wheel_id_list),
            picker_wheel: res.data,
            show_wheel_picker: false,
          });
          if (Number(that.data.is_overlay) === 0) {
            that.setData({
              picker_coupon: false,
              show_coupon_picker: false,
            });
          }
          that.getPrice();
        }
      },
    });
  },

  numSub() {
    return 100;
  },

  toPickAddr(e) {
    let param = e.currentTarget.dataset;
    this.setData({
      chooseAddr: true,
    });
    app.ws_micro_shop_navigate(param);
  },

  showShop() {
    this.dingwei('');
    if (this.data.shop_list_length >= 1) {
      this.setData({
        show_shop: true,
        chooseShop: true,
        show_pay_btn: false,
      });
    }
  },

  showNearestShop() {
    this.dingwei('');
    if (this.data.shop_list_length >= 1) {
      this.setData({
        show_shop: true,
        chooseShop: true,
      });
    }
  },

  pickShop(e) {
    let index = Number(e.currentTarget.dataset.index);
    if (index === -1) {
      this.setData({
        shop: false,
        show_shop: false,
        show_pay_btn: true,
      });
    } else {
      this.setData({
        shop: this.data.shop_list[index],
        show_shop: false,
        show_pay_btn: true
      });
    }
    this.getOrderData(this.data.options);
    this.getPrice();
  },

  integralSwitchChange(e) {
    if (this.data.isMulti) {
      const cb = store => {
        store.integral_radio = e.detail.value ? 1 : 2;
        store.use_integral = e.detail.value ? 1 : 0;
        return store;
      };
      this.prepareMultiData(e, cb);
    } else {
      this.setData({
        integral_radio: e.detail.value ? 1 : 2,
      });
    }
    this.getPrice();
  },

  integration(e) {
    let integration = this.data.integral.integration;
    wx.showModal({
      title: '积分使用规则',
      content: integration,
      showCancel: false,
      confirmText: '我知道了',
      confirmColor: '#ff4544',
    });
  },

  couponShow() {
    let is_overlay = this.data.is_overlay;
    let integration = '优惠券、抽奖券不可同时使用！';
    if (is_overlay === 1) {
      integration = '优惠券、抽奖券可同时使用！';
    }

    wx.showModal({
      title: '商城券使用规则',
      content: integration,
      showCancel: false,
      confirmText: '我知道了',
      confirmColor: '#ff4544',
    });
  },

  getPrice() {
    let {
      isMulti,
      order_info = [],
      integral,
      integral_radio,
      payment,
      card_discount = 0,
      couponPrice,
      gst_rate,
      pst_rate,
      picker_wheel,
      express_price,
      offline,
      pickedCardCoupon: {
        sub_price: cardSubPrice = 0,
        type: cardCouponType = 0,
      } = {},
      isopenmoney,
    } = this.data;
    let total_price2 = couponPrice; // 普通优惠券抵扣的结果
    let new_total_price = total_price2;
    express_price = !isMulti
      ? express_price
      : order_info.map(item => Number(item.express_price));
    integral = !isMulti ? integral : order_info.map(item => item.integral);
    integral_radio = !isMulti
      ? Number(integral_radio)
      : order_info.map(item => item.integral_radio);
    offline = !isMulti ? Number(offline) : order_info.map(item => item.offline);

    // 抽奖暂不做兼容
    picker_wheel && (new_total_price = new_total_price - picker_wheel.credit);

    // 积分抵扣
    if (!isMulti) {
      if (
        integral &&
        integral_radio === 1 &&
        integral.forehead >= integral.integral_least
      ) {
        new_total_price = new_total_price - parseFloat(integral.forehead);
      }
    } else if (integral.length > 0 && integral_radio.length > 0) {
      let integralTotalForehead = 0;
      integral.forEach((v, i) => {
        Number(integral_radio[i]) === 1 &&
          v.forehead >= v.integral_least &&
          (integralTotalForehead += Number(v.forehead));
      });
      new_total_price -= parseFloat(integralTotalForehead);
    }

    if (payment !== 5) {
      cardCouponType = 0;
    }

    // 会员卡优惠券
    cardSubPrice =
      cardCouponType === '1' // 会员卡优惠券
        ? cardSubPrice
        : cardCouponType === '2'
          ? (1 - Number(cardSubPrice) / 10).toFixed(2) * new_total_price // 会员卡在普通优惠券之后扣除
          : 0;
    new_total_price -= cardSubPrice;

    // 会员卡折扣
    let cardDiscount = 0;

    payment === 5 &&
      card_discount >= 0 &&
      (cardDiscount = (1 - card_discount / 10) * new_total_price);
    new_total_price -= cardDiscount;

    // 金额小于零时
    new_total_price < 0 && (new_total_price = 0);

    // 物流处理
    if (!isMulti) {
      if (offline === 0 || offline === 3) {
        new_total_price = parseFloat(new_total_price) + parseFloat(express_price);
      }
    } else {
      let expressArr = [];
      Array.isArray(offline) &&
        (expressArr = order_info.filter(
          item => item.offline === 0 || item.offline === 3
        ));
      expressArr.length > 0 &&
        (new_total_price += expressArr.reduce(
          (a, b) => a + Number(b.express_price),
          0
        ));
    }

    // 税
    (gst_rate > 0 || pst_rate > 0) &&
      (new_total_price = new_total_price + gst_rate + pst_rate);

    this.setData({
      new_total_price: parseFloat(new_total_price).toFixed(2),
      isopenmoney: isopenmoney,
    });
  },

  cardDel() {
    this.setData({
      show_card: false,
    });
    app.util.navigateTo(
      '/ws_micro_shop/pages/order/order',
      { status: 1 },
      true
    );
  },

  cardTo() {
    this.setData({
      show_card: false,
    });
    app.util.navigateTo('/ws_micro_shop/pages/card/card', {}, true);
  },

  formInput(e) {
    let { index } = e.currentTarget.dataset;
    let { form, isMulti } = this.data;

    if (isMulti) {
      const cb = store => {
        let _form = store.form;
        let _formList = _form.list;
        _formList[index].default = e.detail.value;
        store.form.list = _formList;
        return store;
      };
      this.prepareMultiData(e, cb);
    } else {
      let form_list = form.list;
      form_list[index].default = e.detail.value;
      form.list = form_list;
      this.setData({
        form: form,
      });
    }
  },

  selectForm(e) {
    let { storeIndex, index, k } = e.currentTarget.dataset;
    k = Number(k);
    let { form, isMulti, order_info = [] } = this.data;

    let form_list = !isMulti ? form.list : order_info[storeIndex].form.list;
    if (form_list[index].type === 'radio') {
      let default_list = form_list[index].default_list;
      for (let i in default_list) {
        if (Number(i) === k) {
          default_list[k].is_selected = 1;
        } else {
          default_list[i].is_selected = 0;
        }
      }
      form_list[index].default_list = default_list;
    }
    if (form_list[index].type === 'checkbox') {
      let default_list = form_list[index].default_list;
      if (Number(default_list[k].is_selected) === 1) {
        default_list[k].is_selected = 0;
      } else {
        default_list[k].is_selected = 1;
      }
      form_list[index].default_list = default_list;
    }

    if (isMulti) {
      order_info[storeIndex].form.list = form_list;
      this.setData({ order_info });
    } else {
      form.list = form_list;
      this.setData({
        form: form,
      });
    }
  },

  singleChooseForm(e) {
    let { storeIndex, index } = e.currentTarget.dataset;
    let curr = e.detail.value;
    let { form, isMulti, order_info = [] } = this.data;
    let form_list = !isMulti ? form.list : order_info[storeIndex].form.list;

    if (form_list[index].type === 'dropdownlist') {
      let default_list = form_list[index].default_list;
      default_list.forEach(item => {
        item.is_selected = 0;
      });
      // for (let i in default_list) {
      //   default_list[i].is_selected = 0;
      // }
      form_list[index].default = default_list[curr].name;
      default_list[curr].is_selected = 1;
      form_list[index].default_list = default_list;
    }

    if (isMulti) {
      order_info[storeIndex].form.list = form_list;
      this.setData({
        order_info,
      });
    } else {
      form.list = form_list;
      this.setData({
        form,
      });
    }
  },

  showPayment() {
    this.setData({
      // show_payment: true,
    });
  },

  // payPicker(e) {
  //   let index = e.currentTarget.dataset.index;
  //   this.setData({
  //     payment: index,
  //   });
  // },
  payFirst() {
    let that = this;
    let paytype = Number(that.data.payment);
    this.setData({
      paytype: paytype,
    });
    that.paymentRequest(paytype);
  },
  payClose(e) {
    let that = this;
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    let { index } = e.detail;
    let { new_pay_type_list, payment: oldpayment = -1 } = that.data;
    let paytype = Number(new_pay_type_list[index].payment);
    if (Number(oldpayment) === paytype) return;
    that.setData({
      payment: paytype,
      paytype,
      indexNum: app.getpayment(new_pay_type_list, paytype),
    });
    that.paymentRequest(paytype);
  },

  paymentRequest(paytype) {
    let that = this;
    if (paytype === 3) {
      wx.showModal({
        title: '友情提示',
        content: '是否确定选择账户余额支付',
        success: function (res) {
          if (res.confirm) {
            that.getOrderData(that.data.options);
          } else {
            that.setData({
              payment: Number(oldpayment),
            });
          }
        },
      });
    } else if (paytype === 5) {
      let card = that.data.card;
      if (card) {
        that.getOrderData(that.data.options);
      } else {
        wx.showModal({
          title: '友情提示',
          content: '你还未开通会员卡，是否前往个人中心开通？',
          success: function (res) {
            if (res.confirm) {
              app.util.navigateTo('/ws_micro_shop/pages/user/user', {}, false);
            }
          },
        });
      }
    } else {
      that.getOrderData(that.data.options);
    }
  },

  uploadIDCard() {
    let that = this;
    let url = 'utility/file/upload';
    if (url.indexOf('http://') === -1 && url.indexOf('https://') === -1) {
      url = app.util.url(url, { type: 'image', thumb: '0' });
    }
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        let tempFilePaths = res.tempFilePaths[0];
        wx.uploadFile({
          url,
          filePath: tempFilePaths,
          name: 'file',
          success(res) {
            if (res.statusCode === 200) {
              let resp = JSON.parse(res.data);
              app.ws_micro_shoprequest({
                url: api.order.uploadcard,
                data: {
                  url: resp.url,
                },
                success: function(res) {
                  if (res.code === 0) {
                    that.setData({
                      IDcardNo: res.data,
                    });
                  } else {
                    wx.showToast({
                      title: res.msg || '身份证号识别失败',
                      icon: 'none',
                    });
                  }
                },
              });
            }
          },
        });
      },
    });
  },

  chooseTransportType(e) {
    // send_type: 0 || 1 || 2  => 二者 || 仅快递（同城） || 仅自提
    let { storeIndex } = e.currentTarget.dataset;
    let { order_info = [], payment, pay_type_list, isMulti, isRider } = this.data;
    let sendType = order_info[storeIndex].send_type || 0;
    let dispatch_type = Number(order_info[storeIndex].is_shop.dispatch_type) || 0;
    let actionArray =
      dispatch_type === 0 ? [
          isRider ? '骑手配送' : '快递送货', // 0
          '到店自提', // 1
        ]
        : [
          isRider ? '骑手配送' : '同城配送', // 3
          '到店自提', // 1
        ];
    sendType === 1 && actionArray.splice(1, 1); // 仅快递
    sendType === 2 && actionArray.splice(0, 1); // 仅自提

    let offline = 0;
    wx.showActionSheet({
      itemList: actionArray,
      itemColor: '#333',
      success: res => {
        sendType === 0 &&
          (offline =
            dispatch_type === 0
              ? res.tapIndex === 0
                ? 0
                : 1
              : res.tapIndex === 0
                ? 3
                : 1);
        sendType === 1 && (offline = dispatch_type === 0 ? 0 : 3);
        sendType === 2 && (offline = 1);
        order_info[storeIndex].offline = offline;
        order_info[storeIndex].transportType = actionArray[res.tapIndex];
        order_info[storeIndex].showExpressPrice = offline === 1 ? false : true;

        // 切换物流方式时处理支付方式
        let new_pay_type_list = app.getPayTypeList(pay_type_list, offline, order_info, isMulti);
        ((offline !== 1 && payment === 6) || (offline === 1 && payment === 2)) && (payment = new_pay_type_list && new_pay_type_list[0].payment); // 清空支付方式
        this.setData({
          order_info,
          new_pay_type_list,
          payment,
          indexNum: app.getpayment(new_pay_type_list, payment),
          offline,
        });

        this.getPrice();
      },
    });
  },

  prepareMultiData(e, cb) {
    let { storeIndex } = e.currentTarget.dataset;
    let { order_info = [] } = this.data;
    let store = order_info[storeIndex];
    cb && typeof cb === 'function' && (store = cb(store));
    order_info[storeIndex] = store;
    this.setData({ order_info });
  },

  addOnItems(e) {
    let { shopId = 0 } = e.currentTarget.dataset;
    this.data.isMulti && (app.ws_micro_shop_globalData.shopid = shopId);
    app.util.navigateTo('ws_micro_shop/pages/list/list', { from: 'add-on' });
  },

  uploadEvent(e) {
    let { storeIndex, index } = e.currentTarget.dataset;
    let { form, isMulti, order_info = [] } = this.data;
    let form_list = !isMulti ? form.list : order_info[storeIndex].form.list;
    let data = e.detail;
    let imgArr = [];

    if (data) {
      for (let key in data) {
        if (data.hasOwnProperty(key)) {
          imgArr = data[key];
          break;
        }
      }
    }
    if (form_list[index].type === 'uploadimg') {
      form_list[index].default = imgArr;
    }
    if (isMulti) {
      order_info[storeIndex].form.list = form_list;
      this.setData({
        order_info,
      });
    } else {
      form.list = form_list;
      this.setData({
        form,
      });
    }
  },
});
